package com.mallcloud.mall.app.service.impl;

import cn.hutool.core.util.StrUtil;
import com.mallcloud.mall.app.mapper.AppProcedureMapper;
import com.mallcloud.mall.app.service.AppParkingCouponService;
import com.mallcloud.mall.common.core.exception.FailException;
import com.mallcloud.mall.common.data.resolver.TenantResolver;
import com.mallcloud.mall.mall.api.entity.dto.ParkingPointsPayDiscount;
import com.mallcloud.mall.mall.api.entity.dto.ProParkingCouponWriteOff;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 停车券管理
 */
@Service
@RequiredArgsConstructor
public class AppParkingCouponServiceImpl implements AppParkingCouponService {
	private final AppProcedureMapper procedureMapper;

	@Override
	public void parkingCouponWriteOff(ProParkingCouponWriteOff dto) {
		if(StrUtil.isBlank(dto.getStoreNo())){
			dto.setStoreNo(TenantResolver.getById().getCode());
		}
		procedureMapper.redeemCouponWriteOff(dto);
		if (!dto.isSuccess()) throw new FailException(dto.getMessage());
	}

	@Override
	public void parkingPointsDiscount(ParkingPointsPayDiscount dto) {
		if(StrUtil.isBlank(dto.getStoreNo())){
			dto.setStoreNo(TenantResolver.getById().getCode());
		}
		procedureMapper.parkingPointsDiscount(dto);
		if (!dto.isSuccess()) {
			throw new FailException(dto.getMessage());
		}
	}

	@Override
	public void parkingCouponReversal(ProParkingCouponWriteOff dto) {
		if(StrUtil.isBlank(dto.getStoreNo())){
			dto.setStoreNo(TenantResolver.getById().getCode());
		}
		procedureMapper.parkingCouponReversal(dto);
	}

	@Override
	public void parkingPointsDiscountReversal(ParkingPointsPayDiscount dto) {
		if(StrUtil.isBlank(dto.getStoreNo())){
			dto.setStoreNo(TenantResolver.getById().getCode());
		}
		procedureMapper.ParkingPointsDiscountReversal(dto);
	}
}